package hr.ctg.service.dao;

import hr.ctg.domain.model.Mjesto;
import hr.ctg.domain.model.Prognoza;
import hr.jpa.dao.GenericDAOImpl;

import java.util.Date;
import java.util.List;

import javax.persistence.NoResultException;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;

@AutoCreate
@Name("prognozaDAO")
public class PrognozaDAO extends GenericDAOImpl<Prognoza, Integer> {

	@SuppressWarnings("unchecked")
	public List<Prognoza> findLastByIdMjesta(final Integer idMjesta) {
		try {
			return entityManager
					.createNamedQuery("Prognoza.findLastByIdMjesta")
					.setParameter(1, idMjesta).setMaxResults(7).getResultList();
		} catch (final NoResultException e) {
			return null;
		}
	}

	public Prognoza findByMjestoDan(final Mjesto mjesto, final Date dan) {
		try {
			return (Prognoza) entityManager.createNamedQuery(
					"Prognoza.findByMjestoDan").setParameter(1, mjesto)
					.setParameter(2, dan).getSingleResult();
		} catch (final NoResultException e) {
			return null;
		}
	}

}
